package com.ksd.pug.clound.controller;

import com.ksd.pug.clound.api.UserServiceFeign;
import com.ksd.pug.clound.pojo.SysUser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022/2/25 15:47
 */
@RestController
@RequestMapping("/consumer")
@Slf4j
public class UserController {

    @Autowired
    private UserServiceFeign userServiceFeign;

    @GetMapping("/user/{id}")
    @HystrixCommand(fallbackMethod = "fallback")
    public SysUser findUsers(@PathVariable("id") Long id) {
        log.info("===============finusers============");
        if (id == 1L) {
            throw new RuntimeException();
        }
        return userServiceFeign.findUsers(id);
    }


    public SysUser fallback(Long id) {
        SysUser sysUser = new SysUser();
        sysUser.setId(-1000L);
        return sysUser;
    }



//    @HystrixCommand(fallbackMethod = "fallback")
//    @GetMapping("/user/{id}")
//    public SysUser findUsers(@PathVariable("id") Long id) {
//        log.info("===============finusers============");
//        if (id == 1L) {
//            throw new RuntimeException();
//        }
//        return userServiceFeign.findUsers(id);
//    }
//
//    public SysUser fallback(Long id) {
//        SysUser sysUser = new SysUser();
//        sysUser.setId(-1L);
//        return sysUser;
//    }

}
